﻿<template>
    <full-screen-dialog
        title="开票信息录入"
        v-model="visible"
        :width="600"
        destroy-on-close
        :close-on-click-modal="false"
        @closed="$emit('closed')"
    >
        <el-form
            :model="entityObj"
            :rules="rules"
            :disabled="mode == 'Show'"
            ref="dialogForm"
            label-width="100px"
        >

           
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="开票日期" prop="invoiceTime">
                        <el-date-picker
                            style="width: 100%"
                            v-model="entityObj.invoiceTime"
                            type="datetime"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            format="YYYY-MM-DD HH:mm:ss"
                           
                        />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="开票号码" prop="invoiceNo">
                        <el-input v-model="entityObj.invoiceNo" type="text" style="width: 100%"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="开票项目">
                        <el-input v-model="entityObj.invoiceProject" type="text" style="width: 100%"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="开票金额" prop="invoiceAmount">
                        <el-input v-model="entityObj.invoiceAmount" type="text"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="税率">
                        <el-input v-model="entityObj.invoiceTaxRate" type="text"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="税额">
                        <el-input v-model="entityObj.invoiceTaxAmount" type="text"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="发票类型">
                        <el-select placeholder="---请选择发票类型---" v-model="entityObj.invoiceType" style="width: 100%">
                            <el-option v-for="item in optionsInvoiceType" :key="item.value" :label="item.label" :value="item.value" />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
           
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="备注">
                        <el-input v-model="entityObj.remarks" type="textarea" :rows="4" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="附件">
                        <sc-upload-file v-model="entityObj.attachment" :objName="'Supply/BillInvoice'" draggable :uploadType="'OSS'" :bucketName="'jtmc'" :limit="1" />
                    </el-form-item>
                </el-col>
            </el-row>
           
        </el-form>
        <template #footer>
            <el-button @click="visible = false">取 消</el-button>
            <el-button
                v-if="mode != 'Show'"
                type="primary"
                :loading="isSaveing"
                @click="submit()"
            >确 定</el-button>
        </template>
    
    </full-screen-dialog>
</template>

<script>
import tool from "@/utils/tool";
export default {
    emits: ["success", "closed"],
    data() {
        return {
            mode: "Add",
            entityObj: {
                invoiceTime:"",

            },
            visible: false,
            isSaveing: false,
            needSaveFlag: false,
            //验证规则
            rules: {
                invoiceTime: [
                    { required: true, type: "string", message: "请填写开票日期" },
                ],
                invoiceNo: [
                    { required: true, type: "string", message: "请填写发票号码" },
                ],
                invoiceAmount: [
                    { required: true, type: "string", message: "请填写开票金额" },
                ],
            },
            optionsInvoiceType:[],//发票类型
            
        };
    },
   
 
    methods: {
        //显示=
        open(mode = "Add") {
            this.mode = mode;
            this.visible = true;
            return this;
        },
        async setBillId(billId){
             this.entityObj.billId=billId
		}, 
        async setData(data){
            console.log("data",data);
             this.entityObj=data
		}, 
     
        //表单提交方法
        submit() {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    this.isSaveing = true;
                    const data={ ...this.entityObj}
                    console.log("data",data)
                    try {
                        var returnValue =await this.$API.auth.PostProcessApi.post("billInfo/addInvoice",data);
                        if (returnValue.status == 200) {
                            this.$message.success("操作成功");
                            this.$emit("fatherMethod");
                            this.isSaveing = false;
                            this.visible = false;
                        } else {
                            this.$message.error("操作失败:" + returnValue.msg);
                        }
                    } catch (error) {
                        this.loading = false;
                        return false;
                    }
                }
            });
        },
        async initOptions() {
                try {
                    var returnValue = await this.$API.auth.PostProcessApi.post(
                        "base-dictionary/options",
                        { Codes: ["InvoiceType"] }
                    );
                    if (returnValue.status == 200) {
                        this.optionsInvoiceType =returnValue.response.find(p=>p.code=="InvoiceType").optionsDetails;
                    } else {
                        this.$message.error("操作失败:" + returnValue.msg);
                    }
                } catch (error) {
                    this.loading = false;
                    return false;
                }

                
          

        }
       
    },
    async mounted() {
        await this.initOptions();
        this.entityObj.invoiceTime=tool.formatDate(new Date());
        this.entityObj.createId= tool.data.get("USER_INFO").AccountId;
        this.entityObj.createName = tool.data.get("USER_INFO").Name;
        this.entityObj.createTime = tool.formatDate(new Date());

    },
};
</script>
